package com.hd.auto;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ecf.ofc.facade.PreEvaluationImgFacade;
import com.ecf.ofc.facade.dto.PreEvaluationImgBean;
import com.ecf.ofc.facade.request.CreatePreEvaluationImgRequest;
import com.ecf.ofc.facade.response.CreatePreEvaluationImgResponse;

public class LoanReqToOFC {
	
	private static Logger logger = LoggerFactory.getLogger(LoanReqToOFC.class);
	
//	@Reference
//	PreEvaluationImgFacade preEvaluationImgFacade;
	
	@Autowired
	PreEvaluationImgFacade preEvaluationImgFacade;
	
	public void createPreTest(){
		CreatePreEvaluationImgRequest param = new CreatePreEvaluationImgRequest();
		param.setMicroCreditCompId("11111");
		PreEvaluationImgBean preBean = new PreEvaluationImgBean();
		preBean.setExpireTime(getDate(7));
		preBean.setMaxAmount(new BigDecimal(200000));
		preBean.setMinAmount(new BigDecimal(1000));
		preBean.setMemberNo("yu00001");
		preBean.setProductId(10000000l);
		preBean.setProductType(1);
		Byte[] b={0};
		preBean.setStatus(b[0]);
		preBean.setSpecificId("YZ");
		preBean.setStatusReason("yuchuangjian");		
		param.setPreEvaluationImgBean(preBean);
		param.setTrackingNo("sdsd");
//		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-test.xml");
//		PreEvaluationImgFacade preEvaluationImgFacade  = (PreEvaluationImgFacade)ctx.getBean("preEvaluationImgFacade");
		CreatePreEvaluationImgResponse response = preEvaluationImgFacade.createPreEvaluation(param);
		 if (!response.isSuccess()) {
			  System.err.println(response.getMsg());
	          System.err.println("调用预评估接口失败....");
	        }
	}
	
	
	public Date getDate(int d){
		Date endDate;
		try {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Date beginDate = new Date();
		Calendar date = Calendar.getInstance();
		date.setTime(beginDate);
		if(d > 0){
			date.set(Calendar.DATE, date.get(Calendar.DATE) + d);
		}else{
			date.set(Calendar.DATE, date.get(Calendar.DATE) - Math.abs(d));
		}
		date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
		
		
			endDate = dft.parse(dft.format(date.getTime()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return endDate;
	}
	
	public static void main(String[] args) {
		
//		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-test.xml"); 
//		ctx.start();
//		
////		PreEvaluationImgFacade preEvaluationImgFacade = (PreEvaluationImgFacade)ctx.getBean("preEvaluationImgFacade");
//		CreatePreEvaluationImgRequest param = new CreatePreEvaluationImgRequest();
//		System.out.println(preEvaluationImgFacade);
//		preEvaluationImgFacade.createPreEvaluation(param);
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-test.xml");
		context.start();

		LoanReqToOFC lofc= new LoanReqToOFC();
		lofc.createPreTest();

		
		
	}

}
